<?php

namespace app\admin\controller\keesuishoupai;
use app\common\controller\Backend;

/**
 * Ajax
 *
 * @icon fa fa-circle-o
 * @internal
 */
class Ajax extends Backend
{

    /**
     * 模型对象
     */
    protected $model = null;
    protected $noNeedRight = ['*'];

    public function get_path_list()
    {
        $pageList = [
            ['path' => 'https://www.baidu.com', 'name' => '外部链接'],
            ['path' => '/pages/index/index', 'name' => '首页'],
            ['path' => '/pages/user/index', 'name' => '个人中心'],
            ['path' => '/pages/report/submit', 'name' => '事件上报'],
            ['path' => '/pages/report/exposure', 'name' => '曝光台'],
            ['path' => '/pages/user/about', 'name' => '关于我们'],
            ['path' => '/pages/user/agreement', 'name' => '用户协议'],
            ['path' => '/pages/scoreshop/index', 'name' => '积分商城'],
            ['path' => '/pages/user/login', 'name' => '登录'],
        ];        
        $this->view->assign('pageList', $pageList);
        return $this->view->fetch('keesuishoupai/common/pages');
    }
    public function config()
    {
        $name = $this->request->get('name');
        if ($name == 'sms') {
            $config = config('addons.hooks');
            if (isset($config['sms_send']) && $config['sms_send']) {
                $name = reset($config['sms_send']);
            } else {
                $this->error("请在插件管理中安装一款短信验证插件", "");
            }
        } elseif ($name == 'oss') {
            $config = config('addons.hooks');
            if (isset($config['upload_config_init']) && $config['upload_config_init']) {
                $availableArr = array_intersect($config['upload_config_init'], ['alioss', 'bos', 'cos', 'upyun', 'ucloud', 'hwobs', 'qiniu']);
                if ($availableArr) {
                    $name = reset($availableArr);
                }
            }
            if (!$name || $name == 'oss') {
                $this->error("请在插件管理中安装一款云存储插件", "");
            }
        } else {
            $info = get_addon_info($name);
            $addonArr = [
                'third'  => '第三方登录'
            ];
            if (!$info) {
                $this->error('请检查对应插件' . (isset($addonArr[$name]) ? "《{$addonArr[$name]}》" : "") . '是否安装且启动', "");
            }
        }
        $this->redirect('addon/config?name=' . $name . '&dialog=1');
    }
}
